import Vue from 'vue'
import Vuex from 'vuex'
import myInfo from './myInfo'
import mySecretInfo from './mySecretInfo'
import myWallet from './myWallet'


Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    yellowHeaderBg: false,
    loading: false,
    headerTitle: 'AR交友',
    tabIndex: 'arsocial',
    token: localStorage.getItem('token') || null,
    thirdId: localStorage.getItem('thirdId') || null,
    hasAuth: localStorage.getItem('hasAuth') || '0',
    // token: localStorage.getItem('token') || 'Bearer im_65543 16394473990592290628292731938382',
  },
  mutations: {
    personalHeaderBg(state) {
      state.yellowHeaderBg = true;
    },
    defaultHeaderBg(state) {
      state.yellowHeaderBg = false;
    },
    changeHeaderTitle(state, title) {
      state.headerTitle = title;
    },
    selectTabIndex(state, index) {
      state.tabIndex = index;
    },
    showLoading(state) {
      state.loading = true;
    },
    hideLoading(state) {
      state.loading = false;
    },
    setToken(state, token) {
      state.token = token;
      localStorage.setItem('token', token);
    },
    setThirdId(state, thirdId) {
      state.thirdId = thirdId;
      localStorage.setItem('thirdId', thirdId);
    },
    setHasAuth(state, hasAuth) {
      state.hasAuth = hasAuth;
      localStorage.setItem('hasAuth', hasAuth);
    },
    cleanToken(state) {
      state.token = null;
      localStorage.removeItem('token');
      localStorage.removeItem('thirdId');
      localStorage.removeItem('hasAuth');
    },
  },
  actions: {
    showLoading(context) {
      context.commit('showLoading');
    },
    hideLoading(context) {
      context.commit('hideLoading');
    },
    personalHeaderBg(context) {
      context.commit('personalHeaderBg');
    },
    defaultHeaderBg(context) {
      context.commit('defaultHeaderBg');
    },
    changeHeaderTitle(context, title) {
      context.commit('changeHeaderTitle', title);
    },
    selectTabIndex(context, index) {
      context.commit('selectTabIndex', index);
    },
    setToken(context, token) {
      context.commit('setToken', token);
    },
    setThirdId(context, thirdId) {
      context.commit('setThirdId', thirdId);
    },
    setHasAuth(context, hasAuth) {
      context.commit('setHasAuth', hasAuth);
    },
    cleanToken(context) {
      context.commit('cleanToken');
    }
  },
  modules: {
    myInfo,
    mySecretInfo,
    myWallet
  }
})
